package models
{
	import com.adobe.serialization.json.JSON;
	import com.pamakids.manager.LoadManager;

	public class CourseManager
	{
		public function CourseManager()
		{
		}

		public var prevTheme:ThemeVo

		public var prevThemeFolder:ThemeFolderVo

		public function initialize():void
		{
			parse({"coursepacks":
					[
					{"path":"assets/themes/course1","num":3}
					]
				});
			return;
			LoadManager.instance.loadText('assets/course/local.json',loadComplete);
		}

		private function loadComplete(s:String):void
		{
			var o:Object=com.adobe.serialization.json.JSON.decode(s);
			parse(o);
		}

		private function parse(o:Object):void
		{
			mThemeList=[];

			var arr:Array=o.coursepacks;
			for each (var theme:Object in arr) 
			{
				var folder:ThemeFolderVo=new ThemeFolderVo(theme.path,theme.num);
				mThemeList.push(folder);
			}
		}

		public function getThemeList():Array
		{
			return mThemeList;
		}

		public function getThemeDirByType(type:String):ThemeFolderVo
		{
			var arr:Array=getThemeList();
			for (var i:int = 0; i < arr.length; i++) 
			{
				var dir:Object=arr[i];
				if(dir is ThemeFolderVo)
				{
					if (dir.path.indexOf(type)>=0)
					{
						return dir as ThemeFolderVo
					}
				}
			}

			//			for each (var dir:ThemeFolderVo in arr)
			//			{
			//				if (dir.path.indexOf(type)>=0)
			//				{
			//					return dir
			//				}
			//			}
			return null
		}


		private var mThemeList:Array=[]

		private static var mInstance:CourseManager

		public static function getInstance():CourseManager
		{
			return mInstance||=new CourseManager
		}
	}
}

